using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX;

namespace Boids2D
{
    public partial class DXForm : Form
    {
        DXPanel dxPanel;

        internal DXPanel DxPanel
        {
            get { return dxPanel; }
            set { dxPanel = value; }
        }

        public TrackBar TrackBarAvoidMouse
        {
            get { return trackBarAvoid; }
        }
        public TrackBar TrackBarMoveToCenter
        {
            get { return trackBarCenter; }
        }
        public TrackBar TrackBarKeepAway
        {
            get { return trackBarKeepAway; }
        }
        public TrackBar TrackBarMatchVelocity
        {
            get { return trackBarMatch; }
        }
        public TrackBar TrackBarSenseDistance
        {
            get { return trackBarSenseDist; }
        }
        public TrackBar TrackBarSenseAngle
        {
            get { return trackBarSenseAngle; }
        }



        public DXForm()
        {
            InitializeComponent();


            dxPanel = new DXPanel();
            dxPanel.Size = panelPlaceHolder.Size;
            dxPanel.Anchor = panelPlaceHolder.Anchor;
            dxPanel.InitializeDevice();
            dxPanel.BackColor = Color.White;
            this.Controls.Add(dxPanel);
           
        }
        public event EventHandler GoButtonClicked = delegate { };
        private void button1_Click(object sender, EventArgs e)
        {
            GoButtonClicked(sender, e);
        }
      

       
        /*
        private void ChangeVelocity(Boid myBoid)
        {
            double delta;
            delta = rand.NextDouble() * 2 - 1;
            myBoid.Velocity.X += (delta * MAX_ACCEL);
            delta = rand.NextDouble() * 2 - 1;
            myBoid.Velocity.Y += (delta * MAX_ACCEL);

            double mag = myBoid.Velocity.Magnitude();

            if (mag > MAX_VEL)
            {
                myBoid.Velocity = myBoid.Velocity.Multiply(1 / mag).Multiply(MAX_VEL);
            }

        }
         */
        private void AddBoidToMeshList(Boid myBoid)
        {
            Mesh tempMesh = new Mesh();
            //translate the boid mesh to its position


            for (int j = 0; j < myBoid.Mesh.Triangles.Count; j++)
            {
                Triangle tempTri = new Triangle();
                for (int i = 0; i < myBoid.Mesh.Triangles[j].Vertices.Length; i++)
                {
                    float x = myBoid.Mesh.Triangles[j].Vertices[i].X + (float)myBoid.Position.X;
                    float y = myBoid.Mesh.Triangles[j].Vertices[i].Y + (float)myBoid.Position.Y;
                    float z = 0;// myBoid.Mesh.Triangles[j].Vertices[i].Z + (float)myBoid.Position.Z;
                    tempTri.Vertices[i] = new CustomVertex.TransformedColored(x, y, z, 1f, myBoid.Color.ToArgb());

                }
                tempMesh.Triangles.Add(tempTri);

            }
            dxPanel.MeshList.Add(tempMesh);
        }



    }
}
